import backend as TimeTagger
import time
import matplotlib.pyplot as plt
import math
import numpy
import pickle
import sys

sleeptime = 1
print 'which channel? ' ,
channel = int(sys.stdin.readline())
print "Recording Histogram and counters for channels (%d,%d)" % (channel, channel^8)


logger=TimeTagger.Logger()
logger.set_logfile("test.log");
logger.set_dumpfile("dump.log");

ctl = TimeTagger.Control()
overflow = TimeTagger.OverFlow()
overflow.start();

def pass1():
	ctl.start()
	counter=0
	while counter<5:
		counter=counter+1
		print "running pass %d of 10" % counter
		logger.log (logger.DEBUG, "** running test pass %d of 10" % counter)
		h = TimeTagger.Histogram(channel,channel^8,10)
		c1 = TimeTagger.Counter(channel, 10);
		c2 = TimeTagger.Counter(channel^8, 10);
		c1.start()
		c2.start()
		h.start()
		time.sleep(sleeptime)
		h.stop()
	ctl.stop();

def pass2():
	counter=5
	while counter<10:
		counter=counter+1
		print "running pass %d of 10" % (counter)
		logger.log (logger.DEBUG, "** running test pass %d of 10" % counter)
		h = TimeTagger.Histogram(channel,channel^8,10)
		c1 = TimeTagger.Counter(channel, 10);
		c2 = TimeTagger.Counter(channel^8, 10);
		c1.start()
		c2.start()
		h.start()
		ctl.start();
		time.sleep(sleeptime)
		h.stop()
		ctl.stop();

pass1()
pass2()
ctl.shutdown()


